def demo():
    for i in range(4):
        yield i

g=demo()

print(g)#<generator object demo at 0x000001631C7F6C78>
g1=(i for i in g)
print(g1)#<generator object <genexpr> at 0x000001CB59466D68>
g2=(i for i in g1)
print(g2)#<generator object <genexpr> at 0x000001CB59466DE0>

print(list(g1))#[0, 1, 2, 3]
print(list(g2))#[]


def add(n,i):
    return n+i

def test():
    for i in range(4):
        yield i

g=test()
for n in [1,10]:
    g=(add(n,i) for i in g)#两次循环，第二次d的g不会覆盖第一次g的值，因为第一次g没有运行完
    print(1)
print(list(g))

'''
第一次循环：
n=1
g=add(n,i) for i in g)

第二次循环
n=10
g=add(n,i) for i in g)

list(g)==list((add(n,i) for i in g)))
list(g)==list((add(10,i) for i in add(n,i) for i in g))))#第二个n依然为10,
list(g)==list((add(10,i) for i in add(10,i) for i in test()))))
list(g)==list((add(10,i) for i in add(10,i) for i in [0,1,2,3]))))
list(g)==list((add(10,i) for i in [10,11,12,13]))

'''

























